<%@ page contentType="text/html;charset=utf-8"%>
<%@ page language="java" import="java.io.*,java.sql.*,oracle.jdbc.*,java.util.*" %>
<%@ page language="java" import="org.apache.commons.fileupload.*,org.apache.commons.fileupload.disk.*,org.apache.commons.fileupload.servlet.*"%>
<%@ include file="connectionInfo.jsp"%>

<%!
public Connection conn = null;
public PreparedStatement pstmt = null;
public ResultSet rs = null;
public Object[] itemsArray= null;
public int id=0;
public FileItem officedata = null;
public String tempFileDir = "E:\\临时\\" ;    
%>
<%
	id=request.getParameter("id")==null?0:Integer.parseInt(request.getParameter("id").toString().trim());
	String result ="";
	String SqlStr ="";
	FileItem item = null;
	List fileItemsList = null;
	DiskFileItemFactory factory = new DiskFileItemFactory();
	factory.setSizeThreshold(4096);
	factory.setRepository(new File(tempFileDir));
	ServletFileUpload upload = new ServletFileUpload(factory);
	upload.setSizeMax(1024*1024*4);
	fileItemsList = upload.parseRequest(request);
	itemsArray=fileItemsList.toArray();
	if(itemsArray.length==0)
	{out.println("no file upload");return;}
	else
	{
		for(int i=0;i<itemsArray.length;i++)
		{		
			item = (FileItem)itemsArray[i];	
			if(item.getFieldName().equalsIgnoreCase("upLoadFile"))
			{
				officedata=item;
				System.out.println(item.getName()+item.getContentType());
			}
		}
	}
	try
	{
		Class.forName(DBDriver);
	}catch(ClassNotFoundException e)
	{out.println("error"+e.getMessage());return;}
	if(id==0)
	{
		SqlStr="insert into "+officeFileInfoTableName+" (officedate) values(?)";
	}
	else
	{
		SqlStr="update "+officeFileInfoTableName+" set officedate= ? where id="+id;
	}
	System.out.println("SqlStr:"+SqlStr);
	try
	{
		conn = DriverManager.getConnection(ConnStr,userName,userPasswd);    
		pstmt = conn.prepareStatement(SqlStr);		
		pstmt.setBinaryStream(1,officedata.getInputStream(),(int)officedata.getSize());
		pstmt.execute();
		result="success";
	}catch(SQLException e)
	{out.println("error:"+e.getMessage());return;}
	out.println(result);
%>